package com.uhu.code;

/**
 * 560. 和为K的子数组
 * https://leetcode.cn/problems/subarray-sum-equals-k/description/?envType=study-plan-v2&envId=top-100-liked
 */
public class Solution560 {
    public int subarraySum(int[] nums, int k) {
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == k) {
                count++;
            }
            int j = i + 1;
            int temp = nums[i];
            while (j < nums.length) {
                temp = temp + nums[j];
                if (temp == k) {
                    count++;
                }
                j++;
            }
        }
        return count;
    }
}
